-
Notifications
You must be signed in to change notification settings - Fork 22
Fix some optional config file boolean options not being honored #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some optional config file boolean options not being honored #188
Conversation
Boolean CLI options with defaults (keepComments, sortComponentsProps, split) were not being respected when set in a config file. This happened because Commander.js always sets these options to their default values, and the subsequent Object.assign would overwrite config file values with CLI defaults. The fix applies the same pattern already used for lineWidth, sort, and bundle: explicitly check for config file values before the merge, using nullish coalescing to preserve CLI-specified values when present. Co-Authored-By: Claude Opus 4.5 <[email protected]>
67f88a7 to
f04cd0e
Compare
| exports[`openapi-format CLI command should respect boolean options from .openapiformatrc 1`] = ` | ||
| "================================================================================ | ||
| OpenAPI-Format CLI settings: | ||
| - .openapiformatrc: /Users/joseph/oss/openapi-format/.openapiformatrc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rework this, since it should not snapshot your local user path.
|
hi @jdechicchis Nice that you spotted this. The test runs spotted a small issue with your local user ending up in the snapshot: If you correct this, the PR will be included in the next release. |
|
Hi @jdechicchis I merged in your PR and fixed the test, which was a side-effect of the test suite itself. Your PR will be part of the of the next release and thanks again for contributing and using openapi-format 🤝 |
|
FYi @jdechicchis |
|
@thim81 appreciate you making the fix and merging this! |
I noticed that the
keepCommentsoption wasn't being honored when passing a config file like:openapi-format api.yaml -o api.yaml --configFile .openapi-format.json..openapi-format.jsoncontents:Passing the option as a CLI flag worked as expected:
openapi-format api.yaml -o api.yaml --keepComments.Upon some investigation, it appears the source of the bug is with how CLI flags with default values are handled in
bin/cli.js. It looks like there was already special handling for flags likelineWidthandsort. This PR adds similar handling forkeepComments,sortComponentsProps, andsplitNote, this fix could result in the format output differing once folks upgrade their
openapi-formatversion if their current formatting "relied" on these options not being honored when configured via a config file